//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.yuan.java.aliyunapi;


import java.io.File;
import java.net.InetSocketAddress;
import java.net.Proxy;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class ShowapiRequest {
    static {
        System.setProperty("sun.net.http.allowRestrictedHeaders", "true");
    }

    protected int connectTimeout = 3000;
    protected int readTimeout = 15000;
    protected String charset = "utf-8";
    protected String charset_out = "utf-8";
    protected Proxy proxy = null;
    protected boolean printException = true;
    protected boolean allowRedirect = true;
    protected String url;
    protected Map<String, String> textMap = new HashMap();
    protected Map<String, File> uploadMap = new HashMap();
    protected Map<String, String> headMap = new HashMap();
    protected Map<String, List<String>> res_headMap = new HashMap();
    private String appcode;

    public ShowapiRequest(String url, String appcode) {
        this.url = url.trim();
        this.appcode = appcode.trim();
        this.addHeadPara("User-Agent", "showapi_sdk_ali");
        this.addHeadPara("Authorization", "APPCODE " + appcode);
    }

    public String getAppcode() {
        return this.appcode;
    }

    public void setAppcode(String appcode) {
        this.appcode = appcode;
    }

    public boolean isAllowRedirect() {
        return this.allowRedirect;
    }

    public ShowapiRequest setAllowRedirect(boolean allowRedirect) {
        this.allowRedirect = allowRedirect;
        return this;
    }

    public boolean isPrintException() {
        return this.printException;
    }

    public ShowapiRequest setPrintException(boolean printException) {
        this.printException = printException;
        return this;
    }

    public ShowapiRequest setProxy(String proxyIp, int proxyPort) {
        this.proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(proxyIp, proxyPort));
        return this;
    }

    public Proxy getProxy() {
        return this.proxy;
    }

    public String getCharset_out() {
        return this.charset_out;
    }

    public ShowapiRequest setCharset_out(String charset_out) {
        this.charset_out = charset_out;
        return this;
    }

    public Map<String, List<String>> getRes_headMap() {
        return this.res_headMap;
    }

    public void setRes_headMap(Map<String, List<String>> res_headtMap) {
        this.res_headMap = res_headtMap;
    }

    public Map<String, String> getTextMap() {
        return this.textMap;
    }

    public void setTextMap(Map<String, String> textMap) {
        this.textMap = textMap;
    }

    public String getUrl() {
        return this.url;
    }

    public ShowapiRequest setUrl(String url) {
        this.url = url;
        return this;
    }

    public String getCharset() {
        return this.charset;
    }

    public ShowapiRequest setCharset(String charset) {
        this.charset = charset;
        return this;
    }

    public Map<String, File> getUploadMap() {
        return this.uploadMap;
    }

    public void setUploadMap(Map<String, File> uploadMap) {
        this.uploadMap = uploadMap;
    }

    public Map<String, String> getHeadMap() {
        return this.headMap;
    }

    public void setHeadMap(Map<String, String> headMap) {
        this.headMap = headMap;
    }

    public int getConnectTimeout() {
        return this.connectTimeout;
    }

    public ShowapiRequest setConnectTimeout(int connectTimeout) {
        this.connectTimeout = connectTimeout;
        return this;
    }

    public int getReadTimeout() {
        return this.readTimeout;
    }

    public ShowapiRequest setReadTimeout(int readTimeout) {
        this.readTimeout = readTimeout;
        return this;
    }

    public ShowapiRequest addTextPara(String key, String value) {
        this.textMap.put(key, value);
        return this;
    }

    public ShowapiRequest addFilePara(String key, File item) {
        this.uploadMap.put(key, item);
        return this;
    }

    public ShowapiRequest addHeadPara(String key, String value) {
        this.headMap.put(key, value);
        return this;
    }

    public String post() {
        String res = "";

        try {
            res = WebUtils.doPost(this);
        } catch (Exception var3) {
            if (this.printException) {
                var3.printStackTrace();
            }

            res = "{ret_code:-1,error:\"" + var3.toString() + "\"}";
        }

        return res;
    }

    public byte[] postAsByte() {
        byte[] res = null;

        try {
            res = WebUtils.doPostAsByte(this);
        } catch (Exception var5) {
            Exception e = var5;
            if (this.printException) {
                var5.printStackTrace();
            }

            try {
                res = ("{ret_code:-1,error:\"" + e.toString() + "\"}").getBytes("utf-8");
            } catch (Exception var4) {
                if (this.printException) {
                    var4.printStackTrace();
                }
            }
        }

        return res;
    }

    public String get() {
        String res = "";

        try {
            res = WebUtils.doGet(this);
        } catch (Exception var3) {
            if (this.printException) {
                var3.printStackTrace();
            }

            res = "{ret_code:-1,error:\"" + var3.toString() + "\"}";
        }

        return res;
    }

    public byte[] getAsByte() {
        byte[] res = null;

        try {
            res = WebUtils.doGetAsByte(this);
        } catch (Exception var5) {
            Exception e = var5;
            if (this.printException) {
                var5.printStackTrace();
            }

            try {
                res = ("{ret_code:-1,error:\"" + e.toString() + "\"}").getBytes("utf-8");
            } catch (Exception var4) {
                if (this.printException) {
                    var4.printStackTrace();
                }
            }
        }

        return res;
    }


}
